package cn.tsingmo.otproxy.security;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.Security;

/**
 * 初始化安全提供器
 */
public class SecurityProviderInitializer {
    private static final Logger logger = LoggerFactory.getLogger(SecurityProviderInitializer.class);
    private static boolean initialized = false;

    public static synchronized void initialize() {
        if (!initialized) {
            try {
                // 添加Bouncy Castle安全提供器
                Security.addProvider(new BouncyCastleProvider());
                logger.info("Bouncy Castle security provider initialized successfully");
                initialized = true;
            } catch (Exception e) {
                logger.error("Failed to initialize Bouncy Castle security provider", e);
                throw new RuntimeException("Security initialization failed", e);
            }
        }
    }
}